package com.game.gameObject
{
	import com.game.gameHandle.*;
	
	import flash.events.MouseEvent;
	import flash.geom.*;
	
	import mx.containers.Box;
	import mx.controls.TextArea;
	import mx.core.*;
	public class Player extends AnimatedGameObject
	{
		public var speed:Number = 400;
		private var move:GameMove;
		public var startMove:Boolean = false;
		public var width:Number = 32;
		public var height:Number = 32;
		public var name:String;
		public var point:Point;
		public var chatBox:Box = new Box();
		public var chatBoxContent:TextArea = new TextArea();
		
		public function Player(name:String)
		{			
			super();
			this.name = name;
		}
		
		public function startupPlayer():void
		{
			super.startupAnimatedGameObject(ResourceManager.UserGraphics, this.point, ZOrders.PLAYERZORDER);
			this.chatBox.x = this.point.x - 65;
			this.chatBox.y = this.point.y - 55;
			this.chatBox.styleName = 'chatBox';
			
			
			this.chatBoxContent.styleName = 'chatContent';
			this.chatBoxContent.editable = false;
			this.chatBoxContent.id = "chatBoxContent1";

			this.chatBox.addChild(chatBoxContent);
			
			this.chatBox.visible = false;
			
			Application.application.myCanvas.addChild(this.chatBox);
		}
		
		override public function shutdown():void
		{
			super.shutdown();
		}
		
		override public function enterFrame(dt:Number):void
		{
			if (this.startMove) {
				this.move.move();
				this.aniY = this.move.getposY();
				
				this.chatBox.x = this.position.x - 65;
				this.chatBox.y = this.position.y - 55;
				super.enterFrame(dt);
			}
			
		}
		override public function click(event:MouseEvent):void
		{
			var endPosition:Point = new Point(0, 0);
			
			// 得到鼠标位置
			endPosition.x = Application.application.myCanvas.mouseX;
			endPosition.y = Application.application.myCanvas.mouseY;
			
			// 保持在窗口
			if (endPosition.x < 0)
				endPosition.x = 0;
//			if (endPosition.x > Application.application.myCanvas.width - graphics.bitmap.width / graphics.frames)
//				endPosition.x = Application.application.myCanvas.width - graphics.bitmap.width / graphics.frames;
			if (endPosition.y < 0)
				endPosition.y = 0;
//			if (endPosition.y > Application.application.myCanvas.height - graphics.bitmap.height )
//				endPosition.y = Application.application.myCanvas.height - graphics.bitmap.height ;
				
			this.move = new GameMove(this, endPosition);
			this.startMove = true;
									
		}

		
	}
}